package flc.ast.utils;

import com.blankj.utilcode.util.GsonUtils;
import com.blankj.utilcode.util.SPUtils;
import com.google.gson.reflect.TypeToken;

import java.util.ArrayList;
import java.util.List;

import flc.ast.bean.ResumeBean;

public class ResumeDataUtils {
    private static final String SP_NAME = "resumeDataSp";
    private static final SPUtils sSpUtils = SPUtils.getInstance(SP_NAME);

    public static void initModuleData() {
        boolean isInit = sSpUtils.getBoolean("isResumeModuleInit", false);
        if (isInit) return;
        List<ResumeBean.Module> list = new ArrayList<>();
        list.add(new ResumeBean.Module(ModuleCategory.BASIC_INFO.getCode(), "基本信息", true, null));
        list.add(new ResumeBean.Module(ModuleCategory.JOB_INTENTION.getCode(), "求职意向", true, null));
        list.add(new ResumeBean.Module(ModuleCategory.EDUCATION_EXP.getCode(), "教育经历", true, null));
        list.add(new ResumeBean.Module(ModuleCategory.CAMPUS_ACTIVITY.getCode(), "校园活动", false, null));
        list.add(new ResumeBean.Module(ModuleCategory.INTERNSHIP_EXP.getCode(), "实习经历", false, null));
        list.add(new ResumeBean.Module(ModuleCategory.WORK_EXP.getCode(), "工作经历", true, null));
        list.add(new ResumeBean.Module(ModuleCategory.PROJECT_EXP.getCode(), "项目经验", false, null));
        list.add(new ResumeBean.Module(ModuleCategory.PROFESSIONAL_SKILL.getCode(), "专业技能", true, null));
        list.add(new ResumeBean.Module(ModuleCategory.HONORARY_CERTIFICATE.getCode(), "荣誉证书", true, null));
        list.add(new ResumeBean.Module(ModuleCategory.HOBBIES_INTERESTS.getCode(), "兴趣爱好", true, null));
        list.add(new ResumeBean.Module(ModuleCategory.SELF_EVALUATION.getCode(), "自我评价", true, null));
        list.add(new ResumeBean.Module(ModuleCategory.CUSTOM_TITLE.getCode(), "自定义标题", false, null));
        saveModuleList(list);
        sSpUtils.put("isResumeModuleInit", true);
    }

    public static void saveModuleList(List<ResumeBean.Module> list) {
        String json = GsonUtils.toJson(list);
        sSpUtils.put(Key.key_resume_module_list, json);
    }

    public static List<ResumeBean.Module> getModuleList() {
        String json = sSpUtils.getString(Key.key_resume_module_list);
        return GsonUtils.fromJson(json, new TypeToken<List<ResumeBean.Module>>() {
        }.getType());
    }

    public static void saveResumeList(List<ResumeBean> list) {
        String json = GsonUtils.toJson(list);
        sSpUtils.put(Key.key_resume_list, json);
    }

    public static List<ResumeBean> getResumeList() {
        String json = sSpUtils.getString(Key.key_resume_list);
        return GsonUtils.fromJson(json, new TypeToken<List<ResumeBean>>() {
        }.getType());
    }

    interface Key {
        String key_resume_module_list = "key_resume_module_list";
        String key_resume_list = "key_resume_list";

    }
}